﻿using Microsoft.AspNetCore.Mvc;
using System;
using System.Threading.Tasks;
using WaterCloud.Code;
using WaterCloud.Domain.Entity.STZBManage;
using WaterCloud.Service.STZBManage;
using static Serenity.Web.PropertyItemsScript;

namespace WaterCloud.Web.Areas.STZBManage.Controllers
{
    /// <summary>
    /// 账号收藏管理
    /// </summary>
    [Area("STZBManage")]
    public class Account_SCController : BaseController
    {
        public Account_SC_Service _service { get; set; }

        public IActionResult Index()
        {
            return View();
        }

        /// <summary>
        /// 获取账号列表
        /// </summary>
        /// <param name="pagination"></param>
        /// <param name="keyword">关键词</param>
        /// <param name="sell_state">出售状态 1:公示期、2:可购买</param>
        /// <param name="state_val">账号状态</param>
        /// <param name="timeStr">公告日期范围</param>
        /// <param name="userid">当前登入用户id</param>
        /// <param name="monthNum">月数 默认最近一个月</param>
        /// <returns></returns>
        [HandlerAjaxOnly] //ajax校验
        public async Task<ActionResult> Get_Account_SC_GridJson(SoulPage<Account_SC> pagination, string keyword, int sell_state, int state_val, string timeStr, string userid, int monthNum = 1)
        {
            if (string.IsNullOrEmpty(pagination.field))
            {
                pagination.field = "CreateTime";
                pagination.order = "desc";
            }
            var data = await _service.Get_Account_SC_GridJson(pagination, keyword, sell_state, state_val, timeStr, userid, monthNum);
            return Content(pagination.setData(data).ToJson());
        }

        /// <summary>
        /// 删除收藏账号数据
        /// </summary>
        /// <param name="ids">账号数据id</param>
        /// <param name="userid">用户id</param>
        /// <returns></returns>
        [HttpPost]
        [HandlerAjaxOnly] //ajax校验
        [HandlerAuthorize] //权限校验
        public async Task<ActionResult> Delete_Account(string[] ids, string userid)
        {
            try
            {
                await _service.Delete_Account(ids,userid);
                return await Success("操作成功。", "", ids, DbLogType.Delete);
            }
            catch (Exception ex)
            {
                return await Error(ex.Message, "", ids, DbLogType.Delete);
            }
        }
    }
}
